package com.mademoisellegeek.carrentalsimulation;

import com.mademoisellegeek.carrentalsimulation.enums.VehicleStatus;

public class Vehicle implements Cloneable {

    private final int id;
    private int[] garageIdCalendar = new int[365];
    private VehicleStatus[] statusCalendar = new VehicleStatus[365];

    public Vehicle(int id, int garageId) {
        this.id = id;
        for (int i = 0; i < 365; i++) {
            garageIdCalendar[i] = garageId;
        }
        for (int i = 0; i < 365; i++) {
            statusCalendar[i] = VehicleStatus.PARKED;
        }
    }
    
    public Vehicle (int id, int[] garageIdCalendar, VehicleStatus[] statusCalendar) {
        this.id = id;
        this.garageIdCalendar = garageIdCalendar.clone();
        this.statusCalendar = statusCalendar.clone();
    }
    
    @Override
    public Object clone() {
        Vehicle obj = new Vehicle(this.id, this.garageIdCalendar, this.statusCalendar);
        return obj;
    }

    public int getId() {
        return id;
    }

    public void saveTravel(int startDay, int endDay, int garageId) {
            for (int i = startDay - 1; i < endDay; i++) {
                garageIdCalendar[i] = 0;
                statusCalendar[i] = VehicleStatus.TRAVEL;
            }
            for (int i = endDay - 1; i < 365; i++) {
                garageIdCalendar[i] = garageId;
            }
    }
    
    /**
     * @param date
     * @return Garage Id for date
     */
    public int getGarageIdForDay(int date) {
        return garageIdCalendar[date-1];
    }
}